﻿using System;
using System.Web.Mvc;
using SapaFinance.DTO;
using SapaFinance.Services;
using Telerik.Web.Mvc;
using Microsoft.Web.Mvc;

namespace SapaFinance.UI.Controllers
{
    public class CurrencyController : Controller
    {
        private readonly ICurrencyService _currencyService;

        public CurrencyController(ICurrencyService currencyService)
        {
            _currencyService = currencyService;
        }

        public virtual ActionResult RenderCurrency(Guid id)
        {
            return View("EditorTemplates/CurrencyList",  _currencyService.GetSelectedListById(id) );
        }

        public virtual ActionResult Index()
        {
            return View("Index", _currencyService.GetListDTO());
        }

        [HttpPost]
        [GridAction]
        public virtual ActionResult Update(CurrencyDTO dto)
        {
            if (ModelState.IsValid)
            {
                _currencyService.Update(dto);
                return this.RedirectToAction(x => x.Index());
            }
            return Index();
        }

    }
}